--------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  /Users/pabloguzmanpinto/Dropbox/PAME 3ie/Do-files/Logs/5_Prepare variables 2011.log
  log type:  text
 opened on:  14 Dec 2015, 15:30:36

. 
. ************************************************************************************************
> ***********     
. *** 1. Creaci�n de variablestassd
. use "${path_data}/cuestionario2011_adm.dta", clear

. 
. // Consumer price index, depending of month of interview
. 
.         gen ipc_nov2009=100.30

.         gen ipc= 105.52 if date_month==9
(12716 missing values generated)

.         replace ipc= 106.03 if date_month ==10 | date_month==99 /*values 99 are codified to octo
> ber (3 observations)*/
(9253 real changes made)

.         replace ipc= 106.37 if date_month==11
(1295 real changes made)

. 
. 
. 
.         ** Labor income
.                 ** Labor income - primary occupation
.                         * Labor income - primary occupation - wage (monthly for wage earners acc
> ording to d15)
.                         quiet gen ya1_sueldo=0 if ind_c2011==1

.                         quiet replace ya1_sueldo= ya1_sueldo + d15m if (d15m!=. & d15m!=88 & d15
> m!=99)

.                         quiet summ d15m if (d15m<=5000 & d15m!=88 & d15m!=99) , de 

.                         quiet gen rest=1 if (d15m==. | d15m==88 | d15m==99)  /*restriction for t
> his variable*/

.                         replace ya1_sueldo =ya1_sueldo+ r(p50) if d15t==1 & rest==1  /*imputatio
> n of median*/           
(0 real changes made)

.                         replace ya1_sueldo =ya1_sueldo+ 7500 if d15t==2 & rest==1
(5 real changes made)

.                         replace ya1_sueldo=ya1_sueldo+ 12500 if d15t==3 & rest==1
(0 real changes made)

.                         replace ya1_sueldo=ya1_sueldo+ 22500 if d15t==4 & rest==1
(1 real change made)

.                         replace ya1_sueldo= ya1_sueldo + 40000 if d15t==5 & rest==1
(2 real changes made)

.                         replace ya1_sueldo=ya1_sueldo+ 75000 if d15t==6 & rest==1
(4 real changes made)

.                         replace ya1_sueldo=ya1_sueldo+ 125000 if d15t==7 & rest==1
(4 real changes made)

.                         replace ya1_sueldo= ya1_sueldo + 175000 if d15t==8 & rest==1
(22 real changes made)

.                         replace ya1_sueldo= ya1_sueldo + 250000 if d15t==9 & rest==1
(17 real changes made)

.                         replace ya1_sueldo= ya1_sueldo + 350000 if d15t==10 & rest==1
(3 real changes made)

.                         replace ya1_sueldo=ya1_sueldo+ 450000 if d15t==11 & rest==1
(1 real change made)

.                         replace ya1_sueldo=ya1_sueldo+ 550000 if d15t==12 & rest==1
(0 real changes made)

.                         replace ya1_sueldo=ya1_sueldo+ 650000 if d15t==13 & rest==1
(0 real changes made)

.                         replace ya1_sueldo=ya1_sueldo+ 750000 if d15t==14 & rest==1
(0 real changes made)

.                         replace ya1_sueldo=ya1_sueldo+ 850000 if d15t==15 & rest==1
(0 real changes made)

.                         replace ya1_sueldo=ya1_sueldo+ 950000 if d15t==16 & rest==1
(0 real changes made)

.                         replace ya1_sueldo=ya1_sueldo+ 1250000 if d15t==17 & rest==1
(0 real changes made)

.                         replace ya1_sueldo=ya1_sueldo+ 2250000 if d15t==18 & rest==1
(0 real changes made)

.                         summ d15m if (d15m>3000000 & d15m!=.) , de 

        el mes pasado, �cu�l fue el sueldo o salario
             l�quido en su ocupaci�n principal?
-------------------------------------------------------------
      Percentiles      Smallest
 1%      4000000        4000000
 5%      4000000              .
10%      4000000              .       Obs                   1
25%      4000000              .       Sum of Wgt.           1

50%      4000000                      Mean            4000000
                        Largest       Std. Dev.             .
75%      4000000              .
90%      4000000              .       Variance              .
95%      4000000              .       Skewness              .
99%      4000000        4000000       Kurtosis              .

.                         replace ya1_sueldo=ya1_sueldo+ max(3000000,r(p50)) if d15t==19 & rest==1
>   /*imputation of median or CLP 3000000*/
(0 real changes made)

.                         replace ya1_sueldo=. if rest==1 & (d15t==88 | d15t==99)
(110 real changes made, 110 to missing)

.                         replace ya1_sueldo=. if (d05==3 | d05==4 | d05==6 | d05==7 | d05==9) & d
> 15m==. & d15t==. 
(4 real changes made, 4 to missing)

.                         replace ya1_sueldo=0 if d05==8 & ya1_sueldo==.
(1 real change made)

.                         drop rest

.                         
.                                 
.                         * Labor income - primary occupation - business (para indepentents and em
> ployers, variable d16)
.                         quiet gen ya1_negocio=0 if ind_c2011==1

.                         quiet replace ya1_negocio=ya1_negocio + d16m if (d16m!=. & d16m!=88 & d1
> 6m!=99)

.                         quiet summ d16m if (d16m<=5000 & d16m!=88 & d16m!=99) , de 

.                         quiet gen rest=1 if (d16m==. | d16m==88 | d16m==99) /*restriction for th
> is variable*/

.                         replace ya1_negocio =ya1_negocio+ r(p50) if d16t==1 & rest==1  /*imputat
> ion of median*/         
(0 real changes made)

.                         replace ya1_negocio =ya1_negocio+ 7500 if d16t==2 & rest==1
(1 real change made)

.                         replace ya1_negocio=ya1_negocio + 12500 if d16t==3 & rest==1
(3 real changes made)

.                         replace ya1_negocio=ya1_negocio + 22500 if d16t==4 & rest==1
(6 real changes made)

.                         replace ya1_negocio=ya1_negocio + 40000 if d16t==5 & rest==1
(5 real changes made)

.                         replace ya1_negocio=ya1_negocio + 75000 if d16t==6 & rest==1
(12 real changes made)

.                         replace ya1_negocio=ya1_negocio + 125000 if d16t==7 & rest==1
(5 real changes made)

.                         replace ya1_negocio=ya1_negocio + 175000 if d16t==8 & rest==1
(6 real changes made)

.                         replace ya1_negocio= ya1_negocio + 250000 if d16t==9 & rest==1
(4 real changes made)

.                         replace ya1_negocio= ya1_negocio + 350000 if d16t==10 & rest==1
(2 real changes made)

.                         replace ya1_negocio=ya1_negocio+ 450000 if d16t==11 & rest==1
(0 real changes made)

.                         replace ya1_negocio=ya1_negocio+ 550000 if d16t==12 & rest==1
(0 real changes made)

.                         replace ya1_negocio=ya1_negocio+ 650000 if d16t==13 & rest==1
(0 real changes made)

.                         replace ya1_negocio=ya1_negocio+ 750000 if d16t==14 & rest==1
(0 real changes made)

.                         replace ya1_negocio=ya1_negocio+ 850000 if d16t==15 & rest==1
(0 real changes made)

.                         replace ya1_negocio=ya1_negocio+ 950000 if d16t==16 & rest==1
(0 real changes made)

.                         replace ya1_negocio=ya1_negocio+ 1250000 if d16t==17 & rest==1
(0 real changes made)

.                         replace ya1_negocio=ya1_negocio+ 2250000 if d16t==18 & rest==1
(0 real changes made)

.                         summ d16m if (d16m>3000000 & d16m!=.) , de /*no observations*/

      �cu�nto dinero retir� el mes pasado de su negocio
               o actividad para sus gastos o 
-------------------------------------------------------------
no observations

.                         replace ya1_negocio=ya1_negocio+ max(3000000,r(p50)) if d16t==19 & rest=
> =1  /*imputation of median or CLP 3000000*/
(0 real changes made)

.                         replace ya1_negocio=. if rest==1 & (d16t==88 | d16t==99)
(95 real changes made, 95 to missing)

.                         drop rest

.                         replace ya1_negocio=. if (d05==1 | d05==2) & d16m==. & d16t==.
(0 real changes made)

.                                 
.                         * Labor income - primary occupation - business products withdrew for per
> sonal expenses (for indepentents and employers variable d17)
.                         quiet gen ya1_productos=0 if ind_c2011==1

.                         replace ya1_productos=ya1_productos + d17m if (d17m!=. & d17m!=88 & d17m
> !=99)
(404 real changes made)

.                         quiet summ d17m if (d17m<5000 & d17m!=88 & d17m!=99) , de

.                         qui gen rest = 1 if (d17m==. | d17m==88 | d17m==99)

.                         replace ya1_productos =ya1_productos+ r(p50) if d17t==1 & rest==1  /*imp
> utation of median*/             
(0 real changes made)

.                         replace ya1_productos =ya1_productos + 7500 if d17t==2 & rest==1
(3 real changes made)

.                         replace ya1_productos =ya1_productos + 12500 if d17t==3 & rest==1
(1 real change made)

.                         replace ya1_productos=ya1_productos + 22500 if d17t==4 & rest==1
(5 real changes made)

.                         replace ya1_productos=ya1_productos + 40000 if d17t==5 & rest==1
(0 real changes made)

.                         replace ya1_productos=ya1_productos + 75000 if d17t==6 & rest==1
(1 real change made)

.                         replace ya1_productos=ya1_productos + 125000 if d17t==7 & rest==1
(0 real changes made)

.                         replace ya1_productos=ya1_productos + 175000 if d17t==8 & rest==1
(0 real changes made)

.                         replace ya1_productos= ya1_productos + 250000 if d17t==9 & rest==1
(0 real changes made)

.                         replace ya1_productos=ya1_productos + 350000 if d17t==10 & rest==1
(3 real changes made)

.                         replace ya1_productos=ya1_productos+ 450000 if d17t==11 & rest==1
(0 real changes made)

.                         replace ya1_productos=ya1_productos+ 550000 if d17t==12 & rest==1
(0 real changes made)

.                         replace ya1_productos=ya1_productos+ 650000 if d17t==13 & rest==1
(0 real changes made)

.                         replace ya1_productos=ya1_productos+ 750000 if d17t==14 & rest==1
(0 real changes made)

.                         replace ya1_productos=ya1_productos+ 850000 if d17t==15 & rest==1
(0 real changes made)

.                         replace ya1_productos=ya1_productos+ 950000 if d17t==16 & rest==1
(0 real changes made)

.                         replace ya1_productos=ya1_productos+ 1250000 if d17t==17 & rest==1
(0 real changes made)

.                         replace ya1_productos=ya1_productos+ 2250000 if d17t==18 & rest==1
(0 real changes made)

.                         quiet summ d17m if (d17m>3000000 & d17m!=.) , de 

.                         quiet replace ya1_productos=ya1_productos+ max(3000000,r(p50)) if d17t==
> 19 & rest==1  /*imputation of median or CLP 3000000*/

.                         replace ya1_productos=. if rest==1 & (d17t==88 | d17t==99)
(114 real changes made, 114 to missing)

.                         drop rest

.                         replace ya1_productos=. if (d05==1 | d05==2) & d17m==. & d17t==. 
(0 real changes made)

.                         
.                         
.         ** Labor income - secondary occupation
.                         * Labor income - secondary occupation - wage (monthly for wage earners a
> ccording to d28)
.                         quiet gen ya2_sueldo=0 if ind_c2011==1

.                         quiet replace ya2_sueldo= ya2_sueldo + d28m if (d28m!=. & d28m!=88 & d28
> m!=99)

.                         quiet summ d28m if (d28m<5000 & d28m!=88 & d28m!=99) , de

.                         qui gen rest = 1 if (d28m==. | d28m==88 | d28m==99)

.                         quiet replace ya2_sueldo =ya2_sueldo+ r(p50) if d28t==1 & rest==1  /*imp
> utation of median*/             

.                         quiet replace ya2_sueldo =ya2_sueldo + 7500 if d28t==2 & rest==1

.                         quiet replace ya2_sueldo =ya2_sueldo + 12500 if d28t==3 & rest==1

.                         quiet replace ya2_sueldo=ya2_sueldo + 22500 if d28t==4 & rest==1

.                         quiet replace ya2_sueldo=ya2_sueldo + 40000 if d28t==5 & rest==1

.                         quiet replace ya2_sueldo=ya2_sueldo + 75000 if d28t==6 & rest==1

.                         quiet replace ya2_sueldo=ya2_sueldo + 125000 if d28t==7 & rest==1

.                         quiet replace ya2_sueldo=ya2_sueldo + 175000 if d28t==8 & rest==1

.                         quiet replace ya2_sueldo= ya2_sueldo + 250000 if d28t==9 & rest==1

.                         quiet replace ya2_sueldo=ya2_sueldo + 350000 if d28t==10 & rest==1

.                         quiet replace ya2_sueldo=ya2_sueldo+ 450000 if d28t==11 & rest==1

.                         quiet replace ya2_sueldo=ya2_sueldo+ 550000 if d28t==12 & rest==1

.                         quiet replace ya2_sueldo=ya2_sueldo+ 650000 if d28t==13 & rest==1

.                         quiet replace ya2_sueldo=ya2_sueldo+ 750000 if d28t==14 & rest==1

.                         quiet replace ya2_sueldo=ya2_sueldo+ 850000 if d28t==15 & rest==1

.                         quiet replace ya2_sueldo=ya2_sueldo+ 950000 if d28t==16 & rest==1

.                         quiet replace ya2_sueldo=ya2_sueldo+ 1250000 if d28t==17 & rest==1

.                         quiet replace ya2_sueldo=ya2_sueldo+ 2250000 if d28t==18 & rest==1

.                         quiet summ d28m if (d28m>3000000 & d28m!=.) , de 

.                         quiet replace ya2_sueldo=ya2_sueldo+ max(3000000,r(p50)) if d28t==19 & r
> est==1  /*imputation of median or CLP 3000000*/

.                         replace ya2_sueldo=. if rest==1 & (d28t==88 | d28t==99)
(8 real changes made, 8 to missing)

.                         replace ya2_sueldo=. if (d18==3 | d18==4 | d18==5 | d18==6 | d18==7 | d1
> 8==9 ) & d28m==. & d28t==.
(0 real changes made)

.                         replace ya2_sueldo=0 if d18==8 & ya2_sueldo==.
(0 real changes made)

.                         drop rest

.                         
.                         * Labor income - secondary occupation - business (para indepentents and 
> employers, variable d29)
.                         quiet gen ya2_negocio=0 if ind_c2011==1

.                         quiet summ d29m if (d18==1 | d18==2) , de

.                         quiet replace ya2_negocio = ya2_negocio + d29m if (d29m!=. & d29m!=88 & 
> d29m!=99)

.                         quiet summ d29m if (d29m<5000 & d29m!=88 & d29m!=99) , de

.                         quiet gen rest=1 if (d29m==. | d29m==88 | d29m==99)

.                         quiet replace ya2_negocio =ya2_negocio+ r(p50) if d29t==1 & rest==1  /*i
> mputation of median*/           

.                         quiet replace ya2_negocio =ya2_negocio + 7500 if d29t==2 & rest==1

.                         quiet replace ya2_negocio =ya2_negocio + 12500 if d29t==3 & rest==1

.                         quiet replace ya2_negocio=ya2_negocio + 22500 if d29t==4 & rest==1

.                         quiet replace ya2_negocio=ya2_negocio + 40000 if d29t==5 & rest==1

.                         quiet replace ya2_negocio=ya2_negocio + 75000 if d29t==6 & rest==1

.                         quiet replace ya2_negocio=ya2_negocio + 125000 if d29t==7 & rest==1

.                         quiet replace ya2_negocio=ya2_negocio + 175000 if d29t==8 & rest==1

.                         quiet replace ya2_negocio= ya2_negocio + 250000 if d29t==9 & rest==1

.                         quiet replace ya2_negocio=ya2_negocio + 350000 if d29t==10 & rest==1

.                         quiet replace ya2_negocio=ya2_negocio+ 450000 if d29t==11 & rest==1

.                         quiet replace ya2_negocio=ya2_negocio+ 550000 if d29t==12 & rest==1

.                         quiet replace ya2_negocio=ya2_negocio+ 650000 if d29t==13 & rest==1

.                         quiet replace ya2_negocio=ya2_negocio+ 750000 if d29t==14 & rest==1

.                         quiet replace ya2_negocio=ya2_negocio+ 850000 if d29t==15 & rest==1

.                         quiet replace ya2_negocio=ya2_negocio+ 950000 if d29t==16 & rest==1

.                         quiet replace ya2_negocio=ya2_negocio+ 1250000 if d29t==17 & rest==1

.                         quiet replace ya2_negocio=ya2_negocio+ 2250000 if d29t==18 & rest==1

.                         quiet summ d29m if (d29m>3000000 & d29m!=.) , de 

.                         quiet replace ya2_negocio=ya2_negocio+ max(3000000,r(p50)) if d29t==19 &
>  rest==1  /*imputation of median or CLP 3000000*/

.                         replace ya2_negocio=. if rest==1 & (d29t==88 | d29t==99)
(8 real changes made, 8 to missing)

.                         replace ya2_negocio=. if (d18==1 | d18==2) & d29m==. & d29t==.
(120 real changes made, 120 to missing)

.                         drop rest

.                         
.                         * Labor income - secondary occupation - business products withdrew for p
> ersonal expenses (for indepentents and employers variable d30)
.                         quiet gen ya2_productos=0 if ind_c2011==1

.                         quiet replace ya2_productos = ya2_productos + d30m if (d30m!=. & d30m!=8
> 8 & d30m!=99)

.                         quiet summ d30m if (d30m<5000 & d30m!=88 & d30m!=99) , de

.                         quiet gen rest=1 if (d30m==. | d30m==88 | d30m==99)

.                         quiet replace ya2_productos =ya2_productos+ r(p50) if d30t==1 & rest==1 
>  /*imputation of median*/               

.                         quiet replace ya2_productos =ya2_productos + 7500 if d30t==2 & rest==1

.                         quiet replace ya2_productos =ya2_productos + 12500 if d30t==3 & rest==1

.                         quiet replace ya2_productos=ya2_productos + 22500 if d30t==4 & rest==1

.                         quiet replace ya2_productos=ya2_productos + 40000 if d30t==5 & rest==1

.                         quiet replace ya2_productos=ya2_productos + 75000 if d30t==6 & rest==1

.                         quiet replace ya2_productos=ya2_productos + 125000 if d30t==7 & rest==1

.                         quiet replace ya2_productos=ya2_productos + 175000 if d30t==8 & rest==1

.                         quiet replace ya2_productos=ya2_productos + 250000 if d30t==9 & rest==1

.                         quiet replace ya2_productos=ya2_productos + 350000 if d30t==10 & rest==1

.                         quiet replace ya2_productos=ya2_productos+ 450000 if d30t==11 & rest==1

.                         quiet replace ya2_productos=ya2_productos+ 550000 if d30t==12 & rest==1

.                         quiet replace ya2_productos=ya2_productos+ 650000 if d30t==13 & rest==1

.                         quiet replace ya2_productos=ya2_productos+ 750000 if d30t==14 & rest==1

.                         quiet replace ya2_productos=ya2_productos+ 850000 if d30t==15 & rest==1

.                         quiet replace ya2_productos=ya2_productos+ 950000 if d30t==16 & rest==1

.                         quiet replace ya2_productos=ya2_productos+ 1250000 if d30t==17 & rest==1

.                         quiet replace ya2_productos=ya2_productos+ 2250000 if d30t==18 & rest==1

.                         quiet summ d30m if (d30m>3000000 & d30m!=.) , de 

.                         quiet replace ya2_productos=ya2_productos+ max(3000000,r(p50)) if d30t==
> 19 & rest==1  /*imputation of median or CLP 3000000*/

.                         replace ya2_productos=. if rest==1 & (d30t==88 | d30t==99)
(9 real changes made, 9 to missing)

.                         drop rest

.                         replace ya2_productos=. if (d18==1 | d18==2) & d30m==. & d30t==.
(142 real changes made, 142 to missing)

.                          
.                 ** Imputation of missing values for observations with no information on work var
> iables (d01, d02, d03)
.                 foreach x in ya1_sueldo ya1_negocio ya1_productos ya2_sueldo ya2_negocio ya2_pro
> ductos {
  2.                         replace `x' = . if ((d01!=1 & d01!=2) & (d02!=1 & d02!=2) & (d03!=1 &
>  d03!=2)) ///
>                                                                 | ((d01==2) & (d02!=1 & d02!=2) 
> & (d03!=1 & d03!=2)) ///
>                                                                 | ((d01==2) & (d02==2) & (d03!=1
>  & d03!=2)) 
  3.                 }                                       
(3661 real changes made, 3661 to missing)
(3661 real changes made, 3661 to missing)
(3661 real changes made, 3661 to missing)
(3661 real changes made, 3661 to missing)
(3661 real changes made, 3661 to missing)
(3661 real changes made, 3661 to missing)

.                 
.                 
.                 ** Grouping of income coming from primary and secondary occupation
.                 for any 1 2 : egen yaX=  rsum(yaX_sueldo yaX_negocio yaX_productos) if yaX_sueld
> o!=. | yaX_negocio!=. | yaX_productos!=.

->  egen ya1= rsum(ya1_sueldo ya1_negocio ya1_productos) if ya1_sueldo!=. | ya1_negocio!=. | ya1_p
> roductos!=.
(5829 missing values generated)

->  egen ya2= rsum(ya2_sueldo ya2_negocio ya2_productos) if ya2_sueldo!=. | ya2_negocio!=. | ya2_p
> roductos!=.
(5830 missing values generated)

.                 egen ylaborales = rsum(ya1 ya2) if ya1!=. | ya2!=.
(5829 missing values generated)

.                 replace ylaborales=. if ya1_negocio==. &  ya1_productos==. & (d18==10 | d18==99)
(56 real changes made, 56 to missing)

.                 replace ylaborales=. if ya1_negocio==. &  ya1_productos==. & ya2_negocio==. & ya
> 2_productos==.
(3 real changes made, 3 to missing)

.                 replace ylaborales=. if ya1_sueldo==. & (d18==10 | d18==99)
(106 real changes made, 106 to missing)

.                 replace ylaborales=. if ya1_sueldo==. & ya2_sueldo==.
(0 real changes made)

. 
. 
.                 ** Income coming from dependent and independent activities              
.                 egen ydeptes= rsum(ya1_sueldo ya2_sueldo) if (ya1_sueldo!=. | ya2_sueldo!=.)
(5829 missing values generated)

.                 replace ydeptes=. if ya1_sueldo==. & (d18==10 | d18==99)
(106 real changes made, 106 to missing)

.                 replace ydeptes=. if ya1_sueldo==. & ya2_sueldo==.
(0 real changes made)

.                  
.                 egen yindeptes= rsum(ya1_negocio  ya1_productos ya2_negocio  ya2_productos ) if 
> ya1_negocio!=. | ya1_productos!=. | ya2_negocio!=. |  ya2_productos!=.
(5832 missing values generated)

.                 replace yindeptes=. if ya1_negocio==. & ya1_productos==. & (d18==10 | d18==99)
(56 real changes made, 56 to missing)

.                 replace yindeptes=. if ya1_negocio==. & ya1_productos==. & ya2_negocio==. & ya2_
> productos==.
(0 real changes made)

.                 
.                                                         
.         
.         
.         
.         ** Conversion of monetary variables to November 2009 chilean pesos
.         foreach y in ya1_sueldo ya1_negocio ya1_productos ya2_sueldo ya2_negocio ya2_productos y
> a1 ya2 ylaborales ydeptes yindeptes {
  2.                 replace `y'=`y'*(ipc_nov2009/ipc)
  3.         }
(1736 real changes made)
(1703 real changes made)
(417 real changes made)
(36 real changes made)
(269 real changes made)
(42 real changes made)
(3440 real changes made)
(293 real changes made)
(3461 real changes made)
(1756 real changes made)
(1874 real changes made)

.         
.         
.         *** Wage employment, Self-employment and Employment (defined by income of those activiti
> es)
.         gen dependiente = (ydeptes>0) if ind_c2011==1 & ydeptes!=. & yindeptes!=.
(5994 missing values generated)

.         gen independiente = (yindeptes>0) if ind_c2011==1 & ydeptes!=. & yindeptes!=.
(5994 missing values generated)

.         gen trabaja=(ylaborales>0) if ylaborales!=.
(5994 missing values generated)

.         
.         
.         ** Weekly hours worked
.         gen ht=0 if ind_c2011==1
(2168 missing values generated)

.         replace ht=d06                                  if d06!=88 & d06!=99 & d06!=. & ind_c201
> 1==1
(3739 real changes made)

.         replace ht=ht+d19 if d19!=88 & d19!=99 & d19!=. & ind_c2011==1
(377 real changes made)

.     replace ht=.                                                        if (d06==88 | d06==99) &
>  (d19==88 | d19==99 | d19==.)
(110 real changes made, 110 to missing)

. 
.         
.                 
.         ** Demographics
.         ** Years of education
.         quiet gen esc= 0 if (b05t<=2 | b05t==7)

.         quiet replace esc=b05c if (b05t==3 | b05t==5) & (b05c!=88 & b05c!=99 & b05c!=.)

.         quiet replace esc=6 if b05t==4

.         quiet replace esc=8 if b05t==6

.         quiet replace esc=6 + b05c if (b05t==8 | b05t==12) & (b05c!=88 & b05c!=99 & b05c!=.)

.         quiet replace esc=12 if b05t==9 | b05t==11 | b05t==13 | b05t==15

.         quiet replace esc=8 + b05c if (b05t==10 | b05t==14) & (b05c!=88 & b05c!=99 & b05c!=.)

.         quiet replace esc=12 + b05c if (b05t==16 | b05t==17 | b05t==18) & (b05c!=88 & b05c!=99 &
>  b05c!=.)

.         quiet replace esc=17 + b05c if b05t==19 & (b05c!=88 & b05c!=99 & b05c!=.)

.         
. 
.         ** Educational level
.         gen basica= (b05t<=7) if (b05t!=88 & b05t!=99 & b05t!=.)
(2263 missing values generated)

.         gen media_inc= (b05t==8 | b05t==10 | b05t==12 | b05t==14) if (b05t!=88 & b05t!=99 & b05t
> !=.)
(2263 missing values generated)

.         gen media= (b05t==9 | b05t==11 | b05t==13 | b05t==15) if (b05t!=88 & b05t!=99 & b05t!=.)
(2263 missing values generated)

.         gen superior= (b05t>=16 & b05t<=19) if (b05t!=88 & b05t!=99 & b05t!=.)
(2263 missing values generated)

. 
.         
.         ** Age
.         gen edad =  a03 
(2168 missing values generated)

.         
.         
.         ** Gender (1 male, 0 female) 
.         generate sexo= a02
(2168 missing values generated)

.         recode sexo (2 = 0)
(sexo: 6112 changes made)

.         label define sexolbl 1 "Male" 0 "Female"

.         label values sexo sexolbl

.         label var sexo "Dummy Gender (1=Male)"

.         
.                 
.         
.         **********************************************
.         *********Business Practices**************
.         **********************************************
.         
. ** Marketing
. 
. local i=1

. foreach item in 01a 01b 01c 01d 01e 02 03 04 07 {
  2. 
. gen prac_m`i'=0 if ind_c2011==1
  3. replace prac_m`i'=1 if m`item'==1
  4. replace prac_m`i'=. if (m`item'==88 | m`item'==99)
  5. 
. local i=`i'+1
  6. }
(2168 missing values generated)
(3419 real changes made)
(76 real changes made, 76 to missing)
(2168 missing values generated)
(3318 real changes made)
(76 real changes made, 76 to missing)
(2168 missing values generated)
(3692 real changes made)
(86 real changes made, 86 to missing)
(2168 missing values generated)
(1235 real changes made)
(109 real changes made, 109 to missing)
(2168 missing values generated)
(2807 real changes made)
(146 real changes made, 146 to missing)
(2168 missing values generated)
(2570 real changes made)
(88 real changes made, 88 to missing)
(2168 missing values generated)
(3909 real changes made)
(80 real changes made, 80 to missing)
(2168 missing values generated)
(2209 real changes made)
(32 real changes made, 32 to missing)
(2168 missing values generated)
(4618 real changes made)
(105 real changes made, 105 to missing)

. 
. egen marketing=rsum(prac_m1 prac_m2 prac_m3 prac_m4 prac_m5 prac_m6 prac_m7 prac_m8 prac_m9) if 
> ind_c2011==1
(2168 missing values generated)

. replace marketing=. if (prac_m1==. & prac_m2==. & prac_m3==. & prac_m4==. & prac_m5==. & prac_m6
> ==. & prac_m7==. & prac_m8==. & prac_m9==.)
(23 real changes made, 23 to missing)

. 
. 
. * Inventory management
. 
. local i=1

. foreach item in 08 09 10 15 17 {
  2. 
. gen prac_s`i'=0 if ind_c2011==1
  3. replace prac_s`i'=1 if m`item'==1
  4. replace prac_s`i'=. if (m`item'==88 | m`item'==99)
  5. 
. local i=`i'+1
  6. }
(2168 missing values generated)
(2744 real changes made)
(43 real changes made, 43 to missing)
(2168 missing values generated)
(3874 real changes made)
(85 real changes made, 85 to missing)
(2168 missing values generated)
(3634 real changes made)
(101 real changes made, 101 to missing)
(2168 missing values generated)
(2577 real changes made)
(159 real changes made, 159 to missing)
(2168 missing values generated)
(664 real changes made)
(955 real changes made, 955 to missing)

. 
. egen stock=rsum(prac_s1 prac_s2 prac_s3 prac_s4 prac_s5 ) if ind_c2011==1
(2168 missing values generated)

. replace stock=. if (prac_s1==. & prac_s2==. & prac_s3==. & prac_s4==. & prac_s5==.)
(13 real changes made, 13 to missing)

. 
. 
. * Costing and record keeping
. 
. local i=1 

. 
. foreach item in 18 19 20 21 22 23 25 {
  2. 
. gen prac_c`i'=0 if ind_c2011==1
  3. replace prac_c`i'=1 if m`item'==1
  4. replace prac_c`i'=. if (m`item'==88 | m`item'==99)
  5. 
. local i=`i'+1
  6. 
. }
(2168 missing values generated)
(4004 real changes made)
(121 real changes made, 121 to missing)
(2168 missing values generated)
(3857 real changes made)
(178 real changes made, 178 to missing)
(2168 missing values generated)
(3712 real changes made)
(161 real changes made, 161 to missing)
(2168 missing values generated)
(4740 real changes made)
(188 real changes made, 188 to missing)
(2168 missing values generated)
(5365 real changes made)
(171 real changes made, 171 to missing)
(2168 missing values generated)
(2359 real changes made)
(199 real changes made, 199 to missing)
(2168 missing values generated)
(2123 real changes made)
(251 real changes made, 251 to missing)

. 
. egen cost=rsum(prac_c1 prac_c2 prac_c3 prac_c4 prac_c5  prac_c6 prac_c7) if ind_c2011==1
(2168 missing values generated)

. replace cost=. if (prac_c1==. & prac_c2==. & prac_c3==. & prac_c4==. & prac_c5==. & prac_c6==. &
>  prac_c7==.)
(49 real changes made, 49 to missing)

. 
. * Financial planning
. 
. local i=1 

. foreach item in 27 28  {
  2. gen prac_p`i'=0 if ind_c2011==1
  3. replace prac_p`i'=1 if m`item'==1
  4. replace prac_p`i'=. if (m`item'==88 | m`item'==99)
  5. 
. local i=`i'+1
  6. }
(2168 missing values generated)
(4260 real changes made)
(83 real changes made, 83 to missing)
(2168 missing values generated)
(1756 real changes made)
(236 real changes made, 236 to missing)

. 
. gen prac_p3=1 if m26==4  
(9199 missing values generated)

. replace prac_p3=. if ( m26==88 | m26==99) 
(0 real changes made)

.  
. gen prac_p4=1 if (m29a==1 | m29b==1 | m29c==1 | m29d==1 ) 
(10943 missing values generated)

. replace prac_p4=. if (m29a==. & m29b==. & m29c==. & m29d==.) 
(0 real changes made)

. 
. egen plan=rsum(prac_p1 prac_p2 prac_p3 prac_p4 ) 

. replace plan=. if (prac_p1==. & prac_p2==. & prac_p3==. & prac_p4==. ) 
(2234 real changes made, 2234 to missing)

. 
. 
. *** Business practices
. 
. egen tot_practics=rsum(marketing stock cost plan) if ind_c2011==1
(2168 missing values generated)

. replace tot_practics=. if (marketing==. & stock==. & cost==. & plan==. ) 
(7 real changes made, 7 to missing)

. 
. *** Registry book available
. 
. gen ver_registro=1 if m34==1
(12418 missing values generated)

. recode ver_registro .=0
(ver_registro: 12418 changes made)

. replace ver_registro=. if (m34==88 | m34==99)
(57 real changes made, 57 to missing)

. 
. *** Inventory available
. 
. gen ver_inven=1 if m35==1
(12459 missing values generated)

. recode ver_inven .=0
(ver_inven: 12459 changes made)

. replace ver_inven=. if (m35==88 | m35==99)
(51 real changes made, 51 to missing)

. 
. ** Available cash (CLP)
. gen dinero_mano= m30
(6382 missing values generated)

. recode dinero_mano .=0
(dinero_mano: 6382 changes made)

. replace dinero_mano=. if (m30==88 | m30==99)
(733 real changes made, 733 to missing)

. 
. 
. *** Correction of response rates
. *** Variable that identifies self-employment or employers (primary or secondary occupation)
. gen cta_prop=1 if d05==1 | d05==2
(11089 missing values generated)

. replace cta_prop=1 if d18==1 | d18==2
(226 real changes made)

. recode cta_prop .=0
(cta_prop: 10863 changes made)

. 
. *** Variable that identifies who answers Modules G and M of the questionnaire
. gen emprendedor=1 if g01==1
(6382 missing values generated)

. recode emprendedor .=0
(emprendedor: 6382 changes made)

. 
. *** Indicator if responder in Module G, but no independent worker
. gen no_ind_si_emprende=1 if cta_prop==0 & emprendedor==1
(8181 missing values generated)

. recode no_ind_si_emprende .=0
(no_ind_si_emprende: 8181 changes made)

. 
. *** Indicator if not responder in Module G, but independent worker
. 
. gen si_ind_no_emprende=1 if cta_prop==1 & emprendedor==0
(12662 missing values generated)

. recode si_ind_no_emprende .=0
(si_ind_no_emprende: 12662 changes made)

. 
. *** Correction of response rates in business practices
. 
. replace marketing =0 if no_ind_si_emprende==1 & marketing!=. & ind_c2011==1
(4242 real changes made)

. replace stock =0 if no_ind_si_emprende==1 & stock!=.  & ind_c2011==1
(3811 real changes made)

. replace cost =0 if no_ind_si_emprende==1 & cost!=. & ind_c2011==1
(4153 real changes made)

. replace plan=0 if no_ind_si_emprende==1 & plan!=. & ind_c2011==1
(3761 real changes made)

. replace tot_practics=0 if no_ind_si_emprende==1 & tot_practics!=. & ind_c2011==1
(4567 real changes made)

. replace ver_registro=0 if no_ind_si_emprende==1 & ver_registro!=. & ind_c2011==1
(392 real changes made)

. replace ver_inven=0 if no_ind_si_emprende==1 & ver_inven!=. & ind_c2011==1
(361 real changes made)

. replace dinero_mano=0 if no_ind_si_emprende==1 & dinero_mano!=. & ind_c2011==1
(3002 real changes made)

. 
. 
. 
. 
. 
. 
. ************************************************************************************************
> ***********     
. *** 2. Etiquetando vaiables finales
. 
. label var marketing "Indice Practicas Marketing"

. label var stock "Indice Practicas Inventarios"

. label var cost "Indice Practicas de Costo y Registro"

. label var plan "Indice Practicas de Planificacion"

. label var ver_registro "Entrevistador ve libro de registro"

. label var ver_inven "Entrevistador ve Inventarios"

. label var dinero_mano "Dinero a mano para Transacciones"

. label var dependiente "dummy para trabajador dependiente"

. label var independiente "dummy para trabajador independiente"

. label var trabaja "dummy para estar trabajando"

. label var ht "horas semanales trabajadas total"

. label var ylaborales "ingresos laborales"

. label var ydeptes "ingresos provenientes de actividades dependientes"

. label var yindeptes "ingresos provenientes de actividades independientes"

. 
. 
. 
.         
. ************************************************************************************************
> ***********     
. *** 3. Guardando base
.         ** 3.1. Ordeno y guardo base
.         keep id id2010 orden adm_codigo_p ind_c2011 mesp mesp_p C anymesp TT sexo edad esc basic
> a media_inc media superior ydeptes yindeptes ylaborales independiente dependiente trabaja market
> ing stock cost plan tot_pr ver_registro ver_inven dinero_mano ht fichaps

.         
.         
.         sort id orden

.         bysort id : keep if _n== 1
(10298 observations deleted)

. 
. 
.         drop orden

.         sort id

.         
.         save "${path_data}/variables2011", replace
file /Users/pabloguzmanpinto/Dropbox/PAME 3ie/Databases/variables2011.dta saved

.         
.         
. log close
      name:  <unnamed>
       log:  /Users/pabloguzmanpinto/Dropbox/PAME 3ie/Do-files/Logs/5_Prepare variables 2011.log
  log type:  text
 closed on:  14 Dec 2015, 15:30:37
--------------------------------------------------------------------------------------------------
